package com.ilop.permission.base;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.DialogFragment;

import java.util.Objects;

/**
 * @author skygge
 * @date 6/16/22.
 * GitHub：javofxu@github.com
 * email：skygge@yeah.net
 * description：
 */
public abstract class BaseDialogFragment<B extends ViewDataBinding> extends DialogFragment {

    protected final String TAG = getClass().getSimpleName();

    protected B mDBind;

    protected Context mContext;

    protected abstract int initLayoutId();

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = requireContext();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Objects.requireNonNull(getDialog()).requestWindowFeature(Window.FEATURE_NO_TITLE);
        mDBind = DataBindingUtil.inflate(inflater, initLayoutId(), container, false);
        return mDBind.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
        initData();
        initListener();
    }

    protected void initData() {

    }

    protected void initView() {

    }

    protected void initListener() {

    }

    protected ActivityResultLauncher<Intent> mLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> getResultLauncher(result.getData()));

    protected void getResultLauncher(Intent intent) {
    }
}
